import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import IconsResolver from "unplugin-icons/resolver";
// import path from "path";
import Icons from "unplugin-icons/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import { defineConfig } from "vite";
import { viteMockServe } from "vite-plugin-mock";
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [
        IconsResolver({
          enabledCollections: ["ep"]
        }),
        ElementPlusResolver()
      ]
    }),
    viteMockServe({
      mockPath: "mock",
      enable: true
    }),
    Icons({
      autoInstall: true
    })
  ],
  server: {
    host: "0.0.0.0",
    // port: 82,
    open: true,
    cors: true,
    proxy: {
      "/api": {
        target: "https://web.shuhenglib.com/", //
        changeOrigin: true // 允许跨域
        // rewrite: path => path.replace(/^\/api/, '')
      },
      "/depot": {
        // rewrite: (path) => {
        //   console.log("Proxy rewrite:", path); // 添加调试信息
        //   return path.replace(/^\/depot/, "");
        // },
        target: "https://web.shuhenglib.com/", //
        changeOrigin: true // 允许跨域
        // rewrite: path => path.replace(/^\/depot/, '')
      }
    }
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src")
    },
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"]
  }
});
